package com.lidong.rest;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.lidong.entity.Dept;
import com.lidong.service.IDeptService;

/**
 * @Description : 
 * @Author : lidong
 * @Date : 2017年11月2日
 */
@RestController
@RequestMapping("/dept")
public class DeptRest {

	@Autowired
	private IDeptService deptService;
	
	@RequestMapping("/sessionId")
	public String getSessionId(HttpServletRequest request) {
		return request.getSession().getId();
	}
	
	@RequestMapping(value = "/get/{deptNo}", method = RequestMethod.GET)
	public Dept get(@PathVariable long deptNo) {
		return deptService.get(deptNo);
	}
	
	@RequestMapping("/add")
	public Boolean add(@RequestBody Dept dept) {
		return deptService.add(dept);
	}
	
	@RequestMapping("/list")
	public List<Dept> list() {
		return deptService.list();
	}
	
	@RequestMapping("/modify/{deptNo}")
	public Boolean modify(@PathVariable long deptNo, @RequestBody Dept newDept) {
		Dept dept = deptService.get(deptNo);
		dept.setDeptName(newDept.getDeptName());
		return deptService.modify(dept);
	}
	
}
